package sharping.appilog.fragment;

import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class BizMap extends SupportMapFragment {
	
	String name;
	float lat, lng;

	public static BizMap newInstance(String BizName, float lat, float lng) {
		BizMap fragment = new BizMap();

		Bundle bundle = new Bundle();
		bundle.putString("BizName", BizName);
		bundle.putFloat("BizLat", lat);
		bundle.putFloat("BizLng", lng);

		fragment.setArguments(bundle);

		return fragment;
	}

	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		name = getArguments().getString("BizName");
		lat = getArguments().getFloat("BizLat");
		lng = getArguments().getFloat("BizLng");
		
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		try {
			GoogleMap mGoogleMap;
			LatLng loc = new LatLng(Double.valueOf(lat), Double.valueOf(lng));
			CameraPosition cp = new CameraPosition.Builder().target(loc).zoom(15)
					.build();
			
			mGoogleMap = getMap();
			
			mGoogleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cp));
			mGoogleMap.getUiSettings().setScrollGesturesEnabled(false);
			mGoogleMap.getUiSettings().setZoomControlsEnabled(false);
			mGoogleMap.getUiSettings().setZoomGesturesEnabled(false);
			MarkerOptions marker = new MarkerOptions().position(loc);
			marker.title(name);
			// marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_logo));
			mGoogleMap.addMarker(marker).showInfoWindow();
			
		} catch (Exception e) {
			// TODO: handle exception
		}

	}
}
